package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.entity.BaseBuildInfo;
import com.softer.wxzj.entity.BaseHouseInfo;
import com.softer.wxzj.entity.BaseRegionInfo;
import com.softer.wxzj.entity.DepReqListInfo;
import com.softer.wxzj.service.DepReqListInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 交存
 * @author ludexing
 */
@RestController
@RequestMapping("/depReqListInfo")
public class DepReqListInfoController {

    @Autowired
    private DepReqListInfoService depReqListInfoService;

    /**
     * 凭证打印
     *
     * @param page
     * @param depReqListInfo
     * @param fuzzy
     * @return
     */
    @RequestMapping("/getDepReqListInfoListPrint")
    @LogRecord(description = "凭证打印", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<DepReqListInfo> getDepReqListInfoListPrint(Page page, DepReqListInfo depReqListInfo, String fuzzy) {
        return depReqListInfoService.getDepReqListInfoListPrint(page, depReqListInfo, fuzzy);
    }

    /**
     * 公共查询列表
     *
     * @param page
     * @param depReqListInfo
     * @param fuzzy
     * @return
     */
    @RequestMapping("/getDepReqListInfoList")
    @LogRecord(description = "交存维护信息列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<DepReqListInfo> getDepReqListInfoList(Page page, DepReqListInfo depReqListInfo, String fuzzy) {
        return depReqListInfoService.getDepReqListInfoList(page, depReqListInfo, fuzzy);
    }


    /**
     * 缴存维护 两个查询  小区
     *
     * @param page           分页实体
     * @param fuzzy          模糊查询字段
     * @param baseRegionInfo 查询实体 regionName 小区名称
     *                       regionNo 小区编号
     *                       address 地址
     * @return 待维护小区列表
     */
    @RequestMapping("/getRegionInfoList")
    @LogRecord(description = "交存小区信息列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<List<Map>> getRegionInfoList(Page page, String fuzzy, BaseRegionInfo baseRegionInfo) {
        return depReqListInfoService.getRegionInfoList(page, fuzzy, baseRegionInfo);
    }

    /**
     * 小区自然幢交存列表 两个查询
     *
     * @param page          分页实体
     * @param baseBuildInfo 查询实体
     * @return 小区自然幢交存列表
     */
    @RequestMapping("/getBiuldList")
    @LogRecord(description = "小区自然幢交存列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<List<Map>> getBiuldList(Page page, BaseBuildInfo baseBuildInfo) {
        return depReqListInfoService.getBiuldList(page, baseBuildInfo);
    }

    /**
     * 房屋列表  两个查询
     *
     * @param page
     * @param info 缴存模式
     * @return
     */
    @RequestMapping("/getHouseList")
    @LogRecord(description = "小区自然幢交存列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<List<Map>> getHouseList(Page page, BaseHouseInfo info) {
        PageInfo<List<Map>> houseList = depReqListInfoService.getHouseList(page, info);
        return houseList;

    }

    @RequestMapping("/getHouseListByBuilIds")
    @LogRecord(description = "小区自然幢交存列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<List<Map>> getHouseListByBuilIds(Page page, String ids) {
        return depReqListInfoService.getHouseListByBuilIds(page, ids);
    }

    /**
     * 小区自然幢资金补齐
     * @param page
     * @param
     * @return
     */
    @RequestMapping("/getHouseListByBuilIdsByDevelop")
    @LogRecord(description = "小区自然幢资金补齐", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<List<Map>> getHouseListByBuilIdsByDevelop(Page page, BaseHouseInfo baseHouseInfo) {
        return depReqListInfoService.getHouseListByBuilIdsByDevelop(page, baseHouseInfo);
    }

    /**
     * 交存维护
     *
     * @param id      缴存维护的ID
     * @param arcType 图档类型（逗号分隔）
     * @return 缴存维护记录
     */
    @LogRecord(description = "查询一条确定的交存维护", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    @RequestMapping("/getInfo")
    public PageInfo<DepReqListInfo> getInfo(String id, String arcType) {
        PageInfo pageInfo = null;
        DepReqListInfo info = depReqListInfoService.getInfoById(id, arcType);
        /*
            只显示 没删除的 和 已经撤销申请的
         */
        if (info == null || (info.getState().equals(NumStrEnum.ZERO.getNum())&&!("1").equals(info.getFlowState()))) {
            pageInfo = new PageInfo(Arrays.asList());
            pageInfo.setTotal(0);
        } else {
            pageInfo = new PageInfo(Arrays.asList(info));
            pageInfo.setTotal(1);
        }
        return pageInfo;
    }

    /**
     * 根据房屋ID查询交存详情
     *
     * @param id 房屋ID
     * @return 交存详情
     */
    @PostMapping("/getDepositByHouseId")
    public Map getDepositByHouseId(String id, String lid) {
        return depReqListInfoService.getDepositByHouseId(id, lid);
    }

    /**
     * 传 houseID  payAmount  depDate
     *
     * @param depReqListInfo
     * @return
     */
    @RequestMapping("/saveDepReqListInfo")
    @LogRecord(description = "执行缴存保存", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.INSERT)
    public String saveDepReqListInfo(@RequestBody DepReqListInfo depReqListInfo) {
        return depReqListInfoService.save(depReqListInfo);
    }

    /**
     * 批量缴存
     *
     * @param list
     * @return
     */
    @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
    @RequestMapping("/saveDepReqListInfos")
    @LogRecord(description = "执行批量缴存保存", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.INSERT)
    public CommonResult saveDepReqListInfos(@RequestBody List<DepReqListInfo> list) {
        return depReqListInfoService.saveDepReqListInfos(list);
    }

    /**
     * 缴存维护撤销
     *
     * @return
     */
    @RequestMapping("/revocatDepReqList")
    @LogRecord(description = "执行批量撤销", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.INSERT)
    public CommonResult revocatDepReqList(String ids) {
        return depReqListInfoService.revocatDepReqList(ids);
    }

    /**
     * 看该房屋有没有发生过交存
     * getBiuldList
     *
     * @return
     */
    @RequestMapping("/selectCount")
    @LogRecord(description = "看该房屋有没有发生过交存", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public CommonResult selectCount(String houseId) {
        return depReqListInfoService.selectCount(houseId);
    }

    /**
     * 小区自然幢资金补齐提交审核
     * @param list
     * @return
     */
    @RequestMapping("/submitSaveDepReqListInfos")
    @LogRecord(description = "小区自然幢资金补齐提交审核", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public List<String> submitSaveDepReqListInfos( @RequestBody List<DepReqListInfo> list) {
        return depReqListInfoService.submitSaveDepReqListInfos(list);
    }
    /**
     * 小区自然幢资金补齐提交审核
     * @param opinion
     * @return
     */
    @RequestMapping("/addSubmit")
    @LogRecord(description = "小区自然幢资金补齐提交审核", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public CommonResult addSubmit( String opinion,String id,String mark) {
        return depReqListInfoService.addSubmit(opinion,id,mark);
    }

}
